package com.lu.aio.server;

import com.lu.aio.ChannelInitializer;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;

/**
 * @program lu-netty
 * @description: 接受连接处理器
 * @author: zhanglu
 * @create: 2022-06-10 17:29:00
 */
public class AioServerChannelInitializer extends ChannelInitializer {

    private String charset;

    public AioServerChannelInitializer(String charset) {
        this.charset = charset;
    }

    @Override
    protected void initChannel(AsynchronousSocketChannel channel) throws Exception {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        //创建事件(读、写)处理器
        channel.read(buffer, buffer, new AioServerHandler(channel, charset));
    }

}
